/*
Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

// TaskSpec defines the desired state of Task.
type TaskSpec struct {
	//远程服务器IP
	Ip string `json:"ip"`
	//远程服务器端口
	Port int `json:"port"`
	//远程服务器用户名
	Username string `json:"username"`
	//远程服务器私钥base64加密
	// PrivateKey string `json:"privateKey"`
	//远程服务器私钥secret
	PrivateKeySecretRef *corev1.SecretKeySelector `json:"privateKeySecretRef"`
	//任务需要执行的命令
	Command string `json:"command"`
	//任务需要执行的命令的参数
	Args []string `json:"args,omitempty"`
	//定时执行表达式（例如cron格式）
	Schedule string `json:"schedule,omitempty"`
	//外部化配置
	Config string `json:"config,omitempty"`
}

// TaskStatus defines the observed state of Task.
type TaskStatus struct {
	//任务当前状态pending、running、completed、failed
	State string `json:"state"`
	//任务的执行结果
	Result string `json:"result"`
	//最近一次执行时间
	LastRunTime string `json:"lastRunTime"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Namespaced
// +kubebuilder:printcolumn:name="Command",type=string,JSONPath=`.spec.command`
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
// +kubebuilder:printcolumn:name="Result",type=string,JSONPath=`.status.result`
// +kubebuilder:printcolumn:name="LastRunTime",type=string,JSONPath=`.status.lastRunTime`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`

// Task is the Schema for the tasks API.
type Task struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   TaskSpec   `json:"spec,omitempty"`
	Status TaskStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// TaskList contains a list of Task.
type TaskList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Task `json:"items"`
}

func init() {
	SchemeBuilder.Register(&Task{}, &TaskList{})
}
